import {lazy} from "react";
import {Navigate, createHashRouter} from "react-router-dom";

const Home = lazy(() => import("@/pages/home"));
const Login = lazy(() => import("@/pages/login/login"));
const Swiper = lazy(() => import("@/pages/setting/swiper"));
const QuickLink = lazy(() => import("@/pages/setting/quickLink"));
const IndexTabs = lazy(() => import("@/pages/setting/indexTabs"));
const Cagetory = lazy(() => import("@/pages/setting/cagetory"));
const SLCagetory = lazy(() => import("@/pages/setting/SLCagetory"));
const Meituan = lazy(() => import("@/pages/setting/meituan"));
const Verison = lazy(() => import("@/pages/setting/verison"));
const OrderList = lazy(() => import("@/pages/order/list"));
const UserList = lazy(() => import("@/pages/user/List"));
const AdJoin = lazy(() => import("@/pages/user/AdUser"));
const AdvertList = lazy(() => import("@/pages/advert/List"));

const UserDetail = lazy(() => import("@/pages/user/Detail"));
const AdUser = lazy(() => import("@/pages/user/AdUser"));
const Withdrawal = lazy(() => import("@/pages/advert/Withdrawal"));
const GoodsList = lazy(() => import("@/pages/goods/List"));
const GoodsAdd = lazy(() => import("@/pages/goods/Add"));

const settingChildren = [
    {
        path: "/home/setting/swiper",
        element: <Swiper />,
        title: "轮播图配置",
    },
    {
        path: "/home/setting/quick-link",
        element: <QuickLink />,
        title: "快捷导航配置",
    },
    {
        path: "/home/setting/index-tabs",
        element: <IndexTabs />,
        title: "首页Tab配置",
    },
    {
        path: "/home/setting/cagetory",
        element: <Cagetory />,
        title: "首页分类配置",
    },
    {
        path: "/home/setting/second-leve-agetory",
        element: <SLCagetory />,
        title: "二级分类配置",
    },
    {
        path: "/home/setting/meituan",
        element: <Meituan />,
        title: "美团",
    },
    {
        path: "/home/setting/version",
        element: <Verison />,
        title: "过审配置",
    },
];

const userChildren = [
    {
        path: "/home/user/list",
        element: <UserList />,
        title: "用户列表",
        children: [
            {
                path: "/home/user/list/:openId",
                element: <UserDetail />,
                title: "用户详情",
            },
        ],
    },
    {
        path: "/home/user/ad",
        element: <AdUser />,
        title: "推广用户",
    },
    {
        path: "/home/user/join",
        element: <AdJoin />,
        title: "推广位申请",
    },
];
const adChildren = [
    {
        path: "/home/advert/list",
        element: <AdvertList />,
        title: "推广位",
    },
    {
        path: "/home/advert/withdrawal",
        element: <Withdrawal />,
        title: "提现申请",
    },
];

const orderChildren = [
    {
        path: "/home/order/list",
        element: <OrderList />,
        title: "订单列表",
    },
];

const goodsChildren = [
    {
        path: "/home/goods/list",
        title: "商品列表",
        element: <GoodsList />,
    },
    {
        path: "/home/goods/add",
        title: "添加商品",
        element: <GoodsAdd />,
    },
];

const menuList = [
    {
        path: "/home/user",
        title: "用户管理",
        children: userChildren,
    },
    {
        path: "/home/advert",
        title: "推广位管理",
        children: adChildren,
    },
    {
        path: "/home/order",
        title: "订单管理",
        children: orderChildren,
    },
    {
        path: "/home/setting",
        title: "页面配置",
        children: settingChildren,
    },
    {
        path: "/home/goods",
        title: "商品管理",
        children: goodsChildren,
    },
];

const list: any = [
    {
        path: "/",
        element: <Navigate to="/login" />,
    },
    {
        path: "/home",
        element: <Home />,
        loader: () => menuList,
        children: menuList,
    },
    {
        path: "/login",
        element: <Login />,
    },
];

const routers = createHashRouter(list);
export default routers;
